/// 积分套餐模型
class PointsPackageModel {
  /// 套餐ID
  final int id;
  
  /// 积分数量
  final int points;
  
  /// 价格（元）
  final double price;
  
  /// 套餐名称
  final String name;
  
  /// 套餐描述
  final String? description;
  
  /// 是否为热门套餐
  final bool isHot;
  
  PointsPackageModel({
    required this.id,
    required this.points,
    required this.price,
    required this.name,
    this.description,
    this.isHot = false,
  });
  
  factory PointsPackageModel.fromJson(Map<String, dynamic> json) {
    return PointsPackageModel(
      id: json['package_id'] ?? json['id'] ?? 0,
      points: json['points_amount'] ?? json['points'] ?? 0,
      price: (json['price'] ?? 0).toDouble(),
      name: json['package_name'] ?? json['name'] ?? '',
      description: json['package_description'] ?? json['description'],
      isHot: (json['is_popular'] ?? json['is_hot'] ?? 0) == 1,
    );
  }
  
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'points': points,
      'price': price,
      'name': name,
      'description': description,
      'is_hot': isHot,
    };
  }
}

/// 积分套餐响应模型
class PointsPackageResponse {
  final String status;
  final String message;
  final List<PointsPackageModel> packages;
  
  PointsPackageResponse({
    required this.status,
    required this.message,
    required this.packages,
  });
  
  factory PointsPackageResponse.fromJson(Map<String, dynamic> json) {
    // 处理后端返回的 data 字段
    final packagesList = json['data'] ?? json['packages'];
    
    return PointsPackageResponse(
      status: json['status'] ?? 'error',
      message: json['message'] ?? '',
      packages: (packagesList as List<dynamic>?)
          ?.map((item) => PointsPackageModel.fromJson(item))
          .toList() ?? [],
    );
  }
  
  Map<String, dynamic> toJson() {
    return {
      'status': status,
      'message': message,
      'packages': packages.map((p) => p.toJson()).toList(),
    };
  }
}

